/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */

/*This file is prepared for Doxygen automatic documentation generation.*/
/*! \file *********************************************************************
 *
 * \brief AT32UC3B EVK1101 board header file.
 *
 * This file contains definitions and services related to the features of the
 * EVK1101 board rev. A and B.
 *
 * To use this board, define BOARD=EVK1101.
 *
 * - Compiler:           IAR EWAVR32 and GNU GCC for AVR32
 * - Supported devices:  All AVR32 AT32UC3B devices can be used.
 * - AppNote:
 *
 * \author               Atmel Corporation: http://www.atmel.com \n
 *                       Support and FAQ: http://support.atmel.no/
 *
 ******************************************************************************/

/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * 3. The name of Atmel may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * 4. This software may only be redistributed and used in connection with an Atmel
 * AVR product.
 *
 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
 *
 */

#ifndef _GAMEPAD_V1_0d_H_
#define _GAMEPAD_V1_0d_H_

#include "compiler.h"


#ifdef __AVR32_ABI_COMPILER__ // Automatically defined when compiling for AVR32, not when assembling.

#endif  // __AVR32_ABI_COMPILER__


/*! \name Oscillator Definitions
 */
//! @{

// RCOsc has no custom calibration by default. Set the following definition to
// the appropriate value if a custom RCOsc calibration has been applied to your
// part.
//#define FRCOSC          AVR32_PM_RCOSC_FREQUENCY              //!< RCOsc frequency: Hz.

#define FOSC32          32768                                 //!< Osc32 frequency: Hz.
#define OSC32_STARTUP   AVR32_PM_OSCCTRL32_STARTUP_8192_RCOSC //!< Osc32 startup time: RCOsc periods.

#define FOSC0           16000000                              //!< Osc0 frequency: Hz.
#define OSC0_STARTUP    AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC  //!< Osc0 startup time: RCOsc periods.

#define PERIPHERIAL_CLOCK		 28000000

// Osc1 crystal is not mounted by default. Set the following definitions to the
// appropriate values if a custom Osc1 crystal is mounted on your board.
//#define FOSC1           12000000                              //!< Osc1 frequency: Hz.
//#define OSC1_STARTUP    AVR32_PM_OSCCTRL1_STARTUP_2048_RCOSC  //!< Osc1 startup time: RCOsc periods.

//! @}


/*! \name USB Definitions
 */
//! @{

//! Multiplexed pin used for USB_ID: AVR32_USBB_USB_ID_x_x.
//! To be selected according to the AVR32_USBB_USB_ID_x_x_PIN and
//! AVR32_USBB_USB_ID_x_x_FUNCTION definitions from <avr32/uc3bxxxx.h>.
#define USB_ID                      AVR32_USBB_USB_ID_0_0

//! Multiplexed pin used for USB_VBOF: AVR32_USBB_USB_VBOF_x_x.
//! To be selected according to the AVR32_USBB_USB_VBOF_x_x_PIN and
//! AVR32_USBB_USB_VBOF_x_x_FUNCTION definitions from <avr32/uc3bxxxx.h>.
#define USB_VBOF                    AVR32_USBB_USB_VBOF_0_0

//! Active level of the USB_VBOF output pin.
#define USB_VBOF_ACTIVE_LEVEL       LOW

//! USB overcurrent detection pin.
#define USB_OVERCURRENT_DETECT_PIN  AVR32_PIN_PA20

//! @}






/******************** JVM *********************************/



#define HEAP_SIZE		  30000
#define HANDLES_MAX			4000

#define JVM_CLASS_AREA_SIZE 128000

/********************* Timer ***********************************/
#define MAIN_TC_CHANNEL_ID         0
#define MAIN_TC_CHANNEL_PIN        AVR32_TC_A0_0_0_PIN
#define MAIN_TC_CHANNEL_FUNCTION   AVR32_TC_A0_0_0_FUNCTION



/******************** LED *********************************/

#define LED_COUNT 			4

#define LED_0				AVR32_PIN_PB08
#define LED_1				AVR32_PIN_PB09
#define LED_2				AVR32_PIN_PB07
#define LED_3				AVR32_PIN_PA29



/******************************** RFM12 ********************************/



#define RFM12_SPI               (&AVR32_SPI)
#define RFM12_SCK_PIN			AVR32_SPI_SCK_0_1_PIN
#define RFM12_SCK_FUNCTION		AVR32_SPI_SCK_0_1_FUNCTION
#define RFM12_MOSI_PIN			AVR32_SPI_MOSI_0_0_PIN
#define RFM12_MOSI_FUNCTION		AVR32_SPI_MOSI_0_0_FUNCTION
#define RFM12_MISO_PIN			AVR32_SPI_MISO_0_2_PIN
#define RFM12_MISO_FUNCTION		AVR32_SPI_MISO_0_2_FUNCTION
#define RFM12_SELECT_PIN		AVR32_SPI_NPCS_0_0_PIN
#define RFM12_SELECT_FUNCTION	AVR32_SPI_NPCS_0_0_FUNCTION

#define RFM12_SPI_NPCS			0


#define RFM12_IRQ_PIN			AVR32_PIN_PA25




/********************************** BUZZER ***************************************/



#define BUZZER_PWM_PIN             AVR32_PWM_6_0_PIN
#define BUZZER_PWM_FUNCTION        AVR32_PWM_6_0_FUNCTION
#define BUZZER_PWM_CHANNEL_ID      6

#define BUZZER_SOUND_MAX			20

/****************************** UI Keys *******************************/

#define KEY_L_UP				AVR32_PIN_PB05 // OK
#define KEY_L_DOWN			AVR32_PIN_PA12 // OK
#define KEY_L_LEFT			AVR32_PIN_PA11 // Doppelt mit Left
#define KEY_L_RIGHT			AVR32_PIN_PB06 //

#define KEY_R_UP				AVR32_PIN_PA31
#define KEY_R_DOWN			AVR32_PIN_PA10
#define KEY_R_LEFT			AVR32_PIN_PA30
#define KEY_R_RIGHT			AVR32_PIN_PA09

#define KEY_COUNT			8


/****************************** Display *******************************/


#define DISPLAY_USART         (&AVR32_USART0)
#define DISPLAY_CLK_PIN        AVR32_USART0_CLK_0_1_PIN
#define DISPLAY_CLK_FUNCTION   AVR32_USART0_CLK_0_1_FUNCTION
#define DISPLAY_TX_PIN        AVR32_USART0_TXD_0_1_PIN
#define DISPLAY_TX_FUNCTION   AVR32_USART0_TXD_0_1_FUNCTION


#define DISPLAY2D_ROW_SIZE 48
#define DISPLAY2D_ROW_COUNT 8
#define DISPLAY2D_COLUMN_COUNT 8
#define DISPLAY2D_ROW_COUNT 8


#define DISPLAY_XLAT_PIN	AVR32_PIN_PA06
#define DISPLAY_BLANK_PIN	AVR32_PIN_PA07





#define DISPLAY_ROW_SELECT_PIN_2 AVR32_PIN_PA03
#define DISPLAY_ROW_SELECT_PIN_1 AVR32_PIN_PA04
#define DISPLAY_ROW_SELECT_PIN_0 AVR32_PIN_PA05

#define DISPLAY_VCPRG_PIN		 AVR32_PIN_PB10
#define DISPLAY_DCPRG_pin		 AVR32_PIN_PA27

#define DISPLAY2D_ROW_SELECT_MASK		0x7
#define DISPLAY2D_ROW_SELECT_SHIFT		0x3
#define DISPLAY2D_SELECT_PORT			&AVR32_GPIO.port[0]


#define DISPLAY2D_GREEN_START  	12
#define DISPLAY2D_BLUE_START  	24
#define DISPLAY2D_RED_START 	36

#define DISPLAY2D_LED_COUNT				16


#define DISPLAY_TX_PDCA    				AVR32_PDCA_PID_USART0_TX
#define DISPLAY_PDCA_CHANNEL  			1
#define DISPLAY_PDCA_IRQ 				AVR32_PDCA_IRQ_1



#define GS_PWM_CHANNEL_ID 	1
#define GS_PWM_PIN			AVR32_PWM_1_0_PIN
#define GS_PWM_FUNCTION		AVR32_PWM_1_0_FUNCTION


/*********************** ACC **********************************/


#define ACC_USART         (&AVR32_USART2)
#define ACC_CLK_PIN       	 AVR32_USART2_CLK_0_PIN
#define ACC_CLK_FUNCTION  	 AVR32_USART2_CLK_0_FUNCTION
#define ACC_TX_PIN       	 AVR32_USART2_TXD_0_1_PIN
#define ACC_TX_FUNCTION 	 AVR32_USART2_TXD_0_1_FUNCTION

#define ACC_RX_PIN       	AVR32_USART2_RXD_0_1_PIN
#define ACC_RX_FUNCTION 	AVR32_USART2_RXD_0_1_FUNCTION
#define ACC_SS_PIN			AVR32_USART2_RTS_0_PIN
#define ACC_SS_FUNCTION		AVR32_USART2_RTS_0_FUNCTION

#define ACC_IRQ 			AVR32_USART2_IRQ
#endif  // _GAMEPAD_V1_0d_H_
